<?php

namespace app\admin\controller\order;

use ShidianUtil\Thinkphp\Response\ApiResponse;
use ShidianUtil\Utils\CheckUtil;
use app\admin\model\UM as UM;
use app\admin\service\MarginPunishService;
use think\APP;
use think\exception\ValidateException;
use think\Request as Request;

/**
 * MarginPunish 控制器
 * Class MarginPunish
 * @package app\admin\controller\order;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\admin\validate\order\MarginPunish
 */
class MarginPunish
{
    // 请求参数
    private Request $request;

    // service
    private MarginPunishService $service;

    public function __construct(Request $request, MarginPunishService $marginPunishService)
    {
        $this->request = $request;
        $this->service = $marginPunishService;
    }

    /**
     * 新增|修改
     * @param UM $user
     * @return ApiResponse
     * @url /order/margin_punish/save
     */
    public function save(UM $user): ApiResponse
    {
        $request     = $this->request;

        if (!$request->has('id')) {
            throw new ValidateException('请选择一条罚款信息');
        }

        $this->service->modify($user, $request->param('id'), $request->param());

        return ApiResponse::success(null);
    }

}
